<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>The Application - Boost.Outcome documentation</title>
<link rel="stylesheet" href="../../../css/boost.css" type="text/css">
<meta name="generator" content="Hugo 0.52 with Boostdoc theme">
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>

<link rel="icon" href="../../../images/favicon.ico" type="image/ico"/>
<body><div class="spirit-nav">
<a accesskey="p" href="../../../tutorial/advanced/interop/filelib.html"><img src="../../../images/prev.png" alt="Prev"></a>
    <a accesskey="u" href="../../../tutorial/advanced/interop.html"><img src="../../../images/up.png" alt="Up"></a>
    <a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="../../../tutorial/advanced/interop/app-map-httplib1.html"><img src="../../../images/next.png" alt="Next"></a></div><div id="content">
  <div class="titlepage"><div><div><h1 style="clear: both">The Application</h1></div></div></div>
  <p>The application is of course also based on Outcome, and like the HTTP library
is also of mixed-failure design in that failure can be returned via error code,
type erased <code>exception_ptr</code> or indeed a C++ exception throw.</p>

<div class="code-snippet"><div class="highlight"><pre class="chroma"><code class="language-c++" data-lang="c++"><span class="c1">// This is the namespace of the application which is connecting together the httplib,
</span><span class="c1">// filelib and tidylib libraries into a solution.
</span><span class="c1"></span><span class="k">namespace</span> <span class="n">app</span>
<span class="p">{</span>
  <span class="c1">// Create an ADL bridge so copy/move hooks will be searched for in this namespace
</span><span class="c1"></span>  <span class="k">struct</span> <span class="nl">error_code</span> <span class="p">:</span> <span class="k">public</span> <span class="n">std</span><span class="o">::</span><span class="n">error_code</span>
  <span class="p">{</span>
    <span class="c1">// passthrough
</span><span class="c1"></span>    <span class="k">using</span> <span class="n">std</span><span class="o">::</span><span class="n">error_code</span><span class="o">::</span><span class="n">error_code</span><span class="p">;</span>
    <span class="n">error_code</span><span class="p">()</span> <span class="o">=</span> <span class="k">default</span><span class="p">;</span>
    <span class="n">error_code</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">error_code</span> <span class="n">ec</span><span class="p">)</span>
        <span class="o">:</span> <span class="n">std</span><span class="o">::</span><span class="n">error_code</span><span class="p">(</span><span class="n">ec</span><span class="p">)</span>
    <span class="p">{</span>
    <span class="p">}</span>
  <span class="p">};</span>
  <span class="c1">// Localise an outcome implementation for this namespace
</span><span class="c1"></span>  <span class="k">template</span> <span class="o">&lt;</span><span class="k">class</span><span class="err"> </span><span class="nc">T</span><span class="o">&gt;</span>
  <span class="k">using</span> <span class="n">outcome</span> <span class="o">=</span>  <span class="c1">//
</span><span class="c1"></span>  <span class="n">BOOST_OUTCOME_V2_NAMESPACE</span><span class="o">::</span><span class="n">outcome</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span> <span class="n">error_code</span> <span class="cm">/*, std::exception_ptr */</span><span class="o">&gt;</span><span class="p">;</span>
  <span class="k">using</span> <span class="n">BOOST_OUTCOME_V2_NAMESPACE</span><span class="o">::</span><span class="n">success</span><span class="p">;</span>
<span class="p">}</span>  <span class="c1">// namespace app
</span><span class="c1"></span></code></pre></div><a href="https://github.com/boostorg/outcome/tree/master/doc/src/snippets/finale.cpp#L178" class="code-snippet-url" target="_blank">View this code on Github</a></div>


<p>Here we localise a passthrough <code>error_code</code> solely for the purpose of ADL bridging, otherwise
the localised <code>outcome</code> configured is the default one which comes with Outcome.
<a href="../../../tutorial/advanced/hooks/adl_bridging.html">We covered this technique of &ldquo;passthrough <code>error_code</code>&rdquo; earlier in this tutorial</a>.</p>

<p>The way we are going to configure interop is as follows:</p>

<ol>
<li>The application shall use <code>error_code</code> for anticipated failure and C++
exception throws for unanticipated failure.</li>
<li>We shall choose the convention that <code>app::outcome</code> with exception ptr
solely and exclusively represents a type erased failure from a third party
library.</li>
</ol>

<p>Thus if one calls <code>.value()</code> on an <code>app::outcome</code>, both anticipated failure
within the app and type erased failure from a third party library shall be
converted to a C++ exception throw.</p>


        </div><p><small>Last revised: February 11, 2019 at 17:14:51 UTC</small></p>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../../../tutorial/advanced/interop/filelib.html"><img src="../../../images/prev.png" alt="Prev"></a>
    <a accesskey="u" href="../../../tutorial/advanced/interop.html"><img src="../../../images/up.png" alt="Up"></a>
    <a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="../../../tutorial/advanced/interop/app-map-httplib1.html"><img src="../../../images/next.png" alt="Next"></a></div></body>
</html>
